package com.wenan.ui.controls.asMaps
{
	import flash.events.Event;
	import mx.containers.Canvas;
	import mx.controls.Image;
	import mx.core.UIComponent;
	import mx.events.FlexEvent;
	import com.wenan.data.CityCollection;
	import com.wenan.data.ProvinceCollection;
	
	public class NationalMap extends UIComponent
	{
		private var _provinces:ProvinceCollection;
		private var _cities:CityCollection;

		private var _nationalImageSource:Class;
		private var _nationImage:Image;
		
		public function NationalMap()
		{
			super();
			
			_provinces = new ProvinceCollection(this);
//			_cities = new CityCollection(this);
			
			initilizeComponents();	
		}
		
		public function get provinces():ProvinceCollection
		{
			return _provinces;
		}
		
		public function get cities():CityCollection
		{
			return _cities;
		}

		/**
		 * 初始化控件。
		 */
		private function initilizeComponents():void
		{
			_nationImage=new Image();
			_nationImage.addEventListener(FlexEvent.UPDATE_COMPLETE, imageUpdateCompleteHandler);
			_nationImage.addEventListener(Event.RESIZE, resizeImageHandler);
			_nationImage.source=_nationalImageSource;
			addChild(_nationImage);
		}
		
		private function imageUpdateCompleteHandler(event:FlexEvent):void
		{
			try
			{
				var image:Image = event.currentTarget as Image;
				var imageContent:Object = image.content;
				if(imageContent!=null)
				{
					image.width = imageContent.bitmapData.width;
					image.height = imageContent.bitmapData.height;
				}
			}
			catch(e:Error)
			{
			}
		}
		
		private function resizeImageHandler(event:Event):void
		{
			width = _nationImage.width;
			height = _nationImage.height;
		}
			
	}
}